<template>
	<view>
		<view class="kefu" v-if="$text">
				<view>时间：{{datatime}}</view>
		 客服回复： {{$text}}
		</view>
	
		<view class="kefu" v-else >
			<view>时间：{{datatime}}</view>
		 <text >
欢迎光临追光者官方旗舰店~
我是智能客服小李。您可以输入问题或者选择对应序号1、发货时间2、发什么快递3、人工客服
4，如何白嫖

		 </text>
			 
		     
		</view>
		<view class="shuru">
            <input type="text"  v-model="value"  class="input" placeholder="请输入您要查询的问题"/>
			<button class="btn" @click="gomessage" >点击发送</button>		
		</view>
	<!-- <web-view :webview-styles="webviewStyles" src="http://127.0.0.1:8848/ZGZ/htmls/kefu.html" ></web-view> -->
	</view>
</template>
<script>
 import io from '@/until/socket.io.js'
export default {

	data() {
		return {
		         text:'hahah',
				 value:'',//
				 text2:'',
				 datatime:''
				}
			},
			onLoad(e) {
				//获取当前时间
				this.datatime = this.getTime();
				
				if(e.id==1){
					uni.clearStorage('text')
				}
			},
			methods:{
				//获取当前时间
				getTime:function(){
							var date = new Date(),
							year = date.getFullYear(),
							month = date.getMonth() + 1,
							day = date.getDate(),
							hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(),
							minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(),
							second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
							month >= 1 && month <= 9 ? (month = "0" + month) : "";
							day >= 0 && day <= 9 ? (day = "0" + day) : "";
							var timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
							return timer;
						},
				
				
				
				
				gomessage(){
					//链接socket.io服务器
		        let socket=io.connect('http://localhost:3001')
				//接收服务器返回值
	         	socket.on('textmsg',function(data){
				uni.setStorageSync('text',data)
				             //输入框的值给texts
				            this.texts=data
							uni.setStorageSync('text',this.texts)
							window.location.reload()
							console.log(this.texts)
						})
				// console.log(this.value)
				//发送消息给服务器
				   socket.emit('textmsg',this.value)
				
		     	  }
			      }
			
			
			
}
</script>
<style lang="scss">
	page{
		background-image: url('@/static/sort/img/paysuc.webp');
		background-repeat: no-repeat;
		background-size: cover;
		background-attachment: fixed;
	}
	.kefu{
		margin: 6px;
	    padding: 6px;
		border: 1px solid gray;
		font-size: 15px;
		line-height: 50px;
		font-size: 16px;
		line-height: 32px;
		box-shadow: 1px 1px 1px gray;
	}
	
	.shuru{
		    width: 100%;
			height: 40px;
		
		    position: fixed;
		    bottom: 10px;
			display: flex;
			
			.input{
				width: 80%;
				height: 40px;
				border: 1px solid #0aa1ed;
			}
			.btn{
				width: 20%;
				height: 40px;
				border: 1px solid #0aa1ed;
				background-color: #0aa1ed;
				color: white;
			}
	}
	
</style>